using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using BTBookList.Configuration;
using BTBookList.Web;

namespace BTBookList.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class BTBookListDbContextFactory : IDesignTimeDbContextFactory<BTBookListDbContext>
    {
        public BTBookListDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<BTBookListDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            BTBookListDbContextConfigurer.Configure(builder, configuration.GetConnectionString(BTBookListConsts.ConnectionStringName));

            return new BTBookListDbContext(builder.Options);
        }
    }
}
